using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerGroundState : PlayerState
{
    public PlayerGroundState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override void Update()
    {
        base.Update();
        if (Input.GetKeyDown(KeyCode.Mouse1)&&HasNoSword())
        {
            stateMachine.ChangeState(player.aimSword);
        }
        if(Input.GetKey(KeyCode.Mouse0)) {
            stateMachine.ChangeState(player.primeryAttackState);
        }
        if(!player.IsGroundDetected())
        {
            stateMachine.ChangeState(player.airState);
        }
        if(Input.GetKeyDown(KeyCode.Space)&&player.IsGroundDetected()) {
            stateMachine.ChangeState(player.jumpState);        
        }
        
    }

    private bool HasNoSword()
    {
        if (!player.sword)
        {
            return true;
        }
        else
        {
            player.sword.GetComponent<Sword_Skill_Controller>().ReturnSword();
            return false;
        }
    }
}
